{include file="./public/footer" /}
{include file="./public/menu" /}

<!--/sidebar-->
<div class="main-wrap">

    <div class="crumb-wrap">
        <div class="crumb-list"><i class="icon-font"></i><a href="/admin.php">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="/admin.php/group/lists">角色管理</a><span class="crumb-step">&gt;</span><span>新增角色</span></div>
    </div>
    <div class="result-wrap">
        <div class="result-content">
            <form  id="andy_form"  name="myform" enctype="multipart/form-data">
                <table class="insert-tab" width="100%">
                    <tbody>
                    <tr>
                        <th><i class="require-red">*</i>角色名称：</th>
                        <td>
                            <input class="common-text required" id="title" name="group_name" size="50"  type="text">
                        </td>
                    </tr>
                    <tr>
                        <th style="width:150px; height:40px;"><i class="require-red;">*</i>权限分配：</th>
                        <td>
                            {volist name="rule" id="r"}
                            <input type="checkbox" onclick="check(this)" name="rule_id" value="{$r.rule_id}" >&nbsp;{$r.rule_name}&nbsp;&nbsp;
                            {/volist}
                        </td>
                    </tr>




                    <tr>
                        <th>状态：</th>
                        <td>
                            &nbsp;<input type="radio"  value="1" size="85" name="group_status" class="common-text" checked>正常&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;<input type="radio" value="0" name="group_status" size="85" class="commont-text" >停用
                        </td>
                    </tr>


                    <tr>
                        <th></th>
                        <td>
                            <input class="btn btn-primary btn6 mr10" id="andy_group_submit" value="提交" type="button">
                            <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                        </td>
                    </tr>
                    </tbody></table>
            </form>
        </div>
    </div>

</div>
<!--/main-->
<script>

    var SCOPE = {
        'save_url' : '/admin.php/group/add',
        'jump_url' : '/admin.php/group/lists',
    }

    //获取权限
    function check(obj){
        if($(obj).attr('checked')){
            $(obj).attr('checked',false);
        }else{
            $(obj).attr('checked',true);
        }

    }


    //添加
    $("#andy_group_submit").click(function(){
        //获取权限
        var rule_id = [];
        $('input[name="rule_id"]:checked').each(function(){ //遍历，将所有选中的值放到数组中
            rule_id.push($(this).val());
        });
        //获取角色名称
        var groupName = $('input[name="group_name"]').val();
        //获取角色状态
        var groupStatus = $('input[name="group_status"]').val();

        var postData = {rule_id:rule_id,group_name:groupName,group_status:groupStatus};
        //获取提交地址
        var url = SCOPE.save_url;
        //获取返回地址
        var jump_url = SCOPE.jump_url;
        $.post(url,postData,function(result){
            if(result.status == 1) {
                //成功
                return dialog.success(result.message,jump_url);
            }else if(result.status == 0) {
                // 失败
                return dialog.error(result.message);
            }
        },'JSON');
    });


</script>
{include file="Public/bottom" /}